package com.sciology.xpathutility.utils;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;

public final class XPathUtilLog
{

	private XPathUtilLog() {
		// don't touch this
	}
	
	public static void logError(Plugin plugin, String message) {
		log(plugin, IStatus.ERROR, message, null);
	}

	public static void logError(Plugin plugin, String message, Throwable th) {
		log(plugin, IStatus.ERROR, message, th);
	}

	public static void logInfo(Plugin plugin, String message) {
		log(plugin, IStatus.INFO, message, null);
	}

	public static void logInfo(Plugin plugin, String message, Throwable th) {
		log(plugin, IStatus.INFO, message, th);
	}

	public static void log(Plugin plugin, int status, String message, Throwable throwable)
	{
		if (plugin == null) {
			System.err.println(message);				
			if (throwable != null) {		
				throwable.printStackTrace();	
			}
			return;
		}

		plugin.getLog().log(new Status(status, plugin.getBundle().getSymbolicName(), IStatus.OK, message, throwable));
		if (status == IStatus.ERROR) {
			System.err.println(message);	
			if (throwable != null) {
				throwable.printStackTrace();
			}
		}
	}
}
